home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / VBASIC / VBDLH02.ZIP / VBDE_SRC.ZIP / VBDELHA.BAS < prev    next >
Encoding:
BASIC Source File  |  1996-03-08  |  58.4 KB  |  1,233 lines

  1. '===================================================
  2. 'Sample VB program using UNLHA.DLL
  3. 'VBDeLHA.Bas
  4. 'Original: Niiyama(HEROPA) SGV00153@niftyserve.or.jp
  5. 'English : Hitoshi Ozawa   h_ozawa@bekkoame.or.jp
  6. '===================================================
  7. Option Explicit
  8.  
  9. Global Const APP_CAPTION = "VB De UNLHA"
  10. Global Const APP_NAME = "Call UNLHA.DLL from VB"
  11. Global Const APP_DATE = "1995/12/06"
  12. Global Const APP_VERSION = "Version 0.2E"
  13. Global Const APP_COPYRIGHT = "Niiyama(HEROPA)"
  14. Global Const APP_COPYRIGHT2 = "SGV00153@niftyserve.or.jp"
  15. Global Const APP_COPYRIGHT3 = "Hitoshi Ozawa"
  16. Global Const APP_COPYRIGHT4 = "h_ozawa@bekkoame.or.jp"
  17. Global Const APP_COPYRIGHT5 = "http://www.bekkoame.or.jp/~h_ozawa/"
  18. Global Const APP_INIFILE = "Niiyama.Ini"
  19.  
  20. Global gstrLzhFile          As String       'archive file
  21. Global gstrTmpLzhFile       As String       'work file
  22. Global gstrUnpackDir        As String       'extraction directory
  23. Global gintfUnpackCancel    As Integer      'cancel flag for extraction directory
  24. Global gintbSaveFlag        As Integer      'save flag for work file
  25. Global gintbDirFlag         As Integer      'flag checking if extraction directory exists
  26. Global gintbOverWriteFalg   As Integer      'extraction overwrite flag
  27. Global gintbReadOnly        As Integer      'archive file ReadOnly attribute
  28. Global gintWorkCount        As Integer      'number of working extracted files
  29. Global gstrListViewOption   As String       'list display option
  30. Global gstrMRUFile()        As String       'used LZH file
  31. Global gstrHelpFile         As String       'help file
  32. Global gintFileMaxLen       As Integer      'maximum characters in file name in list box
  33.  
  34. Global glngColorBTNHIGHLIGHT    As Long         '3D picture (white)
  35. Global glngColorBTNTEXT         As Long         '3D picture (black)
  36. Global glngColorBTNSHADOW       As Long         '3D picture (dark grey)
  37. Global glngColorBTNFACE         As Long         '3D picture (grey)
  38. Global glngColorWINDOW          As Long         'TipHelp (color of text window)
  39.  
  40. Global gintCXBORDER         As Integer      'system size (frame of form)
  41. Global gintCYBORDER         As Integer      'system size (frame of form)
  42. Global gintCYCAPTION        As Integer      'system size (height of caption)
  43. Global gintCXDLGFRAME       As Integer      'system size (dialog frame)
  44. Global gintCYDLGFRAME       As Integer      'system size (dialog frame)
  45. Global gintCYCURSOR         As Integer      'system size (cursor height)
  46. Global gintCXVSCROLL        As Integer      'system size (width of vertical scroll bar)
  47. Global gintCYHSCROLL        As Integer      'system size (height of horizontal scroll bar)
  48.  
  49. Global gintWinVer           As Integer      'Windows version
  50. Global gintbTipHelp         As Integer      'TipHelp option flag
  51. Global gintParenthWnd       As Integer      'TipHelp parent window handle referring to frmToolTip
  52. Global gintTiphWnd          As Integer      'TipHelp parent control handle
  53.  
  54. '-------------------------------------------------------------------
  55. 'Constant declaration to call Help
  56. Global Const HLP_MAIN = &H0&
  57. Global Const HLP_GAIYOU = &H100&
  58. Global Const HLP_INSTALL = &H200&
  59. Global Const HLP_KAKUBU = &H300&
  60. Global Const HLP_ETC = &H400&
  61. Global Const HLP_HISTORY = &H500&
  62. Global Const HLP_COPYRIGHT = &H600&
  63. Global Const HLP_MNUFILENEW = &H311&
  64. Global Const HLP_MNUFILEOPEN = &H312&
  65. Global Const HLP_MNUFILESAVE = &H313&
  66. Global Const HLP_MNUFILESAVEAS = &H314&
  67. Global Const HLP_MNUFILESFX = &H315&
  68. Global Const HLP_MNUFILEEXIT = &H316&
  69. Global Const HLP_MNUEDITUNDO = &H321&
  70. Global Const HLP_MNUEDITALLSELECT = &H322&
  71. Global Const HLP_MNUEDITPACK = &H323&
  72. Global Const HLP_MNUEDITUNPACK = &H324&
  73. Global Const HLP_MNUEDITDELETE = &H325&
  74. Global Const HLP_MNUEDITTEST = &H326&
  75. Global Const HLP_MNUVIEWCONFIG = &H331&
  76. Global Const HLP_MNUVIEWTIPHELP = &H332&
  77. Global Const HLP_MNUVIEWINFO = &H333&
  78. Global Const HLP_MNUVIEWRUN = &H334&
  79. Global Const HLP_MNUVIEWTEXT = &H335&
  80. Global Const HLP_MNUHELPCONTENTS = &H341&
  81. Global Const HLP_MNUHELPSEARCH = &H342&
  82. Global Const HLP_MNUHELPON = &H343&
  83. Global Const HLP_MNUHELPABOUT = &H344&
  84. Global Const HLP_DLGVIEWCONFIG = &H700&
  85. Global Const HLP_DLGCHOOSEDIR = &H800&
  86. Global Const HLP_DLGABOUT = &H900&
  87.  
  88. '-------------------------------------------
  89. Type tagPoint
  90.     X       As Integer
  91.     y       As Integer
  92. End Type
  93.  
  94. Type tagRECT
  95.     Left    As Integer
  96.     Top     As Integer
  97.     Right   As Integer
  98.     Bottom  As Integer
  99. End Type
  100.  
  101. Global gtagTxtViewRECT As tagRECT
  102.  
  103. ' Define open file information
  104. Type tagOFSTRUCT
  105.     strBytes     As String * 1               ' size of OFSTRUCT structure in bytes
  106.     strFixedDisk As String * 1               ' flag checking if file is on hard disk
  107.     intErrCode   As Integer                  ' error value when OpenFile failed
  108.     strReserved  As String * 4               ' reserved
  109.     strPathName  As String * 128             ' file path
  110. End Type
  111.  
  112. Type tagWINDOWPLACEMENT
  113.     length              As Integer
  114.     flags               As Integer
  115.     showCmd             As Integer
  116.     ptMinPosition       As tagPoint
  117.     ptMaxPosition       As tagPoint
  118.     rcNormalPosition    As tagRECT
  119. End Type
  120.  
  121. '-------------------------------------------
  122. Global Const GFSR_SYSTEMRESOURCES = &H0      ' free system resource
  123. Global Const SW_SHOWNA = 8
  124. Global Const SW_RESTORE = 9
  125. Global Const SW_HIDE = 0
  126. Global Const SWP_NOSIZE = &H1
  127. Global Const SWP_NOMOVE = &H2
  128. Global Const SWP_NOACTIVATE = &H10
  129. Global Const SWP_SHOWWINDOW = &H40
  130. Global Const HWND_TOPMOST = -1
  131. Global Const HWND_NOTOPMOST = -2
  132. Global Const SM_CXBORDER = 5        'width of window frame
  133. Global Const SM_CYBORDER = 6        'width of vertical component of window frame
  134. Global Const SM_CYCAPTION = 4       'height of form caption
  135. Global Const SM_CXDLGFRAME = 7      'width of horizontal component of dialog box frame
  136. Global Const SM_CYDLGFRAME = 8      'width of vertical component of dialog box frame
  137. Global Const SM_CXFULLSCREEN = 16   'width of client area when window is maximized
  138. Global Const SM_CYFULLSCREEN = 17   'height of client aread when window is maximized
  139. Global Const SM_CYCURSOR = 14       'height of mouse cursor
  140. Global Const SM_CXVSCROLL = 2       'width of vertical scroll bar
  141. Global Const SM_CYHSCROLL = 3       'height of horizontal scroll bar
  142. Global Const COLOR_BTNFACE = 15         'shadow of push button
  143. Global Const COLOR_BTNHIGHLIGHT = 20    'selected button in control
  144. Global Const COLOR_BTNSHADOW = 16       'green shadow of push button
  145. Global Const COLOR_BTNTEXT = 18         'push button text
  146. Global Const COLOR_WINDOW = 5
  147. Global Const WM_USER = &H400
  148. Global Const EM_SETREADONLY = (WM_USER + 31)            'set text box write attribute
  149. Global Const LB_SETHORIZONTALEXTENT = (WM_USER + 21)    'set horizontal scroll bar to a list box
  150. Global Const LB_SETSEL = (WM_USER + 6)                  'list box selection status
  151. Global Const LB_SETTABSTOPS = (WM_USER + 19)            'list box tags
  152. Global Const OF_EXIST = &H4000               ' close file immediately after opening it
  153. Global Const SRCAND = &H8800C6      ' (DWORD) dest = source AND dest
  154. Global Const SRCINVERT = &H660046   ' (DWORD) dest = source XOR dest
  155. Global Const GWW_HINSTANCE = (-6)
  156. Global Const MF_BYPOSITION = &H400
  157. 'Help
  158. Global Const HELP_CONTEXT = &H1           'Help topics
  159. Global Const HELP_QUIT = &H2              'Quit Help file
  160. Global Const HELP_INDEX = &H3             'Index
  161. 'Global Const HELP_CONTENTS = &H3
  162. Global Const HELP_HELPONHELP = &H4        'How to use help
  163. 'Global Const HELP_SETINDEX = &H5          'current index
  164. 'Global Const HELP_SETCONTENTS = &H5
  165. 'Global Const HELP_CONTEXTPOPUP = &H8
  166. 'Global Const HELP_FORCEFILE = &H9
  167. Global Const HELP_KEY = &H101             'keyword search
  168. Global Const HELP_COMMAND = &H102
  169. Global Const HELP_PARTIALKEY = &H105
  170. 'Global Const HELP_MULTIKEY = &H201
  171.  
  172. '-------------------------------------------
  173. Declare Sub GetCursorPos Lib "User" (lppt As tagPoint)
  174. Declare Sub GetWindowRect Lib "User" (ByVal hWnd As Integer, lprc As tagRECT)
  175. Declare Function ShowWindow Lib "User" (ByVal hWnd As Integer, ByVal nCmdShow As Integer) As Integer
  176. Declare Function GetActiveWindow Lib "User" () As Integer
  177. Declare Function FindWindow Lib "User" (ByVal lpClassName As Any, ByVal lpszWindow As Any) As Integer
  178. Declare Function GetLastActivePopup Lib "User" (ByVal hwndOwnder As Integer) As Integer
  179. Declare Function BringWindowToTop Lib "User" (ByVal hWnd As Integer) As Integer
  180. Declare Function SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hwndInsertAfter As Integer, ByVal X As Integer, ByVal y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal fuFlag As Integer) As Integer
  181. 'Needed to display Windows3.1 information with version
  182. Declare Sub ShellAbout Lib "Shell" (ByVal hWnd As Integer, ByVal lpAppName As String, ByVal lpMoreInfo As String, ByVal hIcon As Integer)
  183.  
  184. Declare Function GetSystemMetrics Lib "User" (ByVal nIndex As Integer) As Integer
  185. Declare Function GetSysColor Lib "User" (ByVal nDspElement As Integer) As Long
  186.  
  187. Declare Function SendMessage Lib "User" (ByVal hWnd As Integer, ByVal uMsg As Integer, ByVal wParam As Integer, lParam As Any) As Long
  188.  
  189. ' file creation, open, modification, deletion
  190. Declare Function OpenFile Lib "Kernel" (ByVal lpszFilename As String, lpOpenBuff As tagOFSTRUCT, ByVal fuMode As Integer) As Integer
  191.  
  192. Declare Function BitBlt Lib "Gdi" (ByVal hdcDest As Integer, ByVal nXDest As Integer, ByVal nYDest As Integer, ByVal nWidth As Integer, ByVal nHeight As Integer, ByVal hdcSrc As Integer, ByVal nXSrc As Integer, ByVal nYSrc As Integer, ByVal dwRop As Long) As Integer
  193.  
  194. 'for CTL3D.DLL
  195. Declare Function GetModuleHandle Lib "Kernel" (ByVal lpszModuleName As String) As Integer
  196. Declare Function GetWindowWord Lib "User" (ByVal hWnd As Integer, ByVal nOffset As Integer) As Integer
  197.  
  198. Declare Function Ctl3dRegister Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer
  199. Declare Function Ctl3dAutoSubClass Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer
  200. Declare Function Ctl3dUnregister Lib "CTL3D.DLL" (ByVal hInstance As Integer) As Integer
  201. Declare Function Ctl3dGetVer Lib "CTL3D.DLL" () As Integer
  202.  
  203. Declare Function ExtractIcon Lib "Shell" (ByVal hinst As Integer, ByVal lpszExeName As String, ByVal iIcon As Integer) As Integer
  204.  
  205. Declare Function GetTempFileName Lib "Kernel" (ByVal cDriveLetter As Integer, ByVal lpPrefixString As String, ByVal wUnique As Integer, ByVal lpTempFileName As String) As Integer
  206.  
  207. Declare Function GetVersion Lib "Kernel" () As Long
  208.  
  209. Declare Function WritePrivateProfileString Lib "Kernel" (ByVal lpszSection As String, ByVal lpszEntry As String, ByVal lpszString As String, ByVal lpszFilename As String) As Integer
  210. Declare Function GetPrivateProfileInt Lib "Kernel" (ByVal lpszSection As String, ByVal lpszEntry As String, ByVal default As Integer, ByVal lpszFilename As String) As Integer
  211. Declare Function GetPrivateProfileString Lib "Kernel" (ByVal lpszSection As String, ByVal lpszEntry As String, ByVal lpszDefault As String, ByVal lpszReturnBuffer As String, ByVal cbReturnBuffer As Integer, ByVal lpszFilename As String) As Integer
  212.  
  213. Declare Function GetWindowPlacement Lib "User" (ByVal hWnd As Integer, lpwndpl As tagWINDOWPLACEMENT) As Integer
  214. Declare Function SetWindowPlacement Lib "User" (ByVal hWnd As Integer, lpwndpl As tagWINDOWPLACEMENT) As Integer
  215.  
  216. Declare Function DeleteMenu Lib "User" (ByVal hMenu As Integer, ByVal nPosition As Integer, ByVal wFlags As Integer) As Integer
  217. Declare Function GetSystemMenu Lib "User" (ByVal hWnd As Integer, ByVal bRevert As Integer) As Integer
  218. Declare Function GetSubMenu Lib "User" (ByVal hMenu As Integer, ByVal nPos As Integer) As Integer
  219. Declare Function GetMenu Lib "User" (ByVal hWnd As Integer) As Integer
  220. Declare Function TrackPopupMenu Lib "User" (ByVal hMenu As Integer, ByVal wFlags As Integer, ByVal X As Integer, ByVal y As Integer, ByVal nReserved As Integer, ByVal hWnd As Integer, lpReserved As Any) As Integer
  221.  
  222.  
  223. Declare Function FindExecutable Lib "Shell" (ByVal lpszFile As String, ByVal lpszDir As String, ByVal lpszResult As String) As Integer
  224. Declare Function WinExec Lib "Kernel" (ByVal lpCmdLine As String, ByVal nCmdShow As Integer) As Integer
  225. Declare Function GetModuleUsage Lib "Kernel" (ByVal hModule As Integer) As Integer
  226.  
  227. ' Get percentage of free system resource
  228. Declare Function GetFreeSystemResources Lib "User" (ByVal fuSysResource As Integer) As Integer
  229.  
  230. Declare Function WinHelp Lib "User" (ByVal hWnd As Integer, ByVal lpzHelpFile As String, ByVal fuCommand As Integer, dwData As Any) As Integer
  231. '-------------------------------------------
  232. 'Visual Basic 3.0 Constant.Txt
  233.  
  234. ' Show method
  235. Global Const MODAL = 1                  'modal
  236. 'Global Const MODELESS = 0              'modeless
  237.  
  238. ' MsgBox parameter
  239. Global Const MB_OK = 0                 ' OK button only
  240. Global Const MB_OKCANCEL = 1           ' OK and cancel buttons
  241. Global Const MB_ABORTRETRYIGNORE = 2   ' cancel, retry, and ignore buttons
  242. Global Const MB_YESNOCANCEL = 3        ' yes, no, and cancel buttons
  243. Global Const MB_YESNO = 4              ' yes and no buttons
  244. Global Const MB_RETRYCANCEL = 5        ' retry and cancel buttons
  245.  
  246. Global Const MB_ICONSTOP = 16          ' Stop
  247. Global Const MB_ICONQUESTION = 32      ' Question
  248. Global Const MB_ICONEXCLAMATION = 48   ' Exclamation
  249. Global Const MB_ICONINFORMATION = 64   ' Information
  250.  
  251. Global Const MB_APPLMODAL = 0          ' application modal
  252. Global Const MB_DEFBUTTON1 = 0         ' set button1 to default
  253. Global Const MB_DEFBUTTON2 = 256       ' set button2 to default
  254. 'Global Const MB_DEFBUTTON3 = 512      ' set button3 to default
  255. 'Global Const MB_SYSTEMMODAL = 4096    ' system mode
  256.  
  257. ' Return code from MsgBox button
  258. Global Const IDOK = 1                  ' OK button
  259. Global Const IDCANCEL = 2              ' cancel button
  260. Global Const IDABORT = 3               ' abort button
  261. Global Const IDRETRY = 4               ' retry button
  262. Global Const IDIGNORE = 5              ' ignore button
  263. Global Const IDYES = 6                 ' yes button
  264. Global Const IDNO = 7                  ' no button
  265.  
  266. ' SetAttr, Dir, GetAttr functions
  267. 'Global Const ATTR_NORMAL = 0           ' normal file
  268. Global Const ATTR_READONLY = 1          ' read-only file
  269. 'Global Const ATTR_HIDDEN = 2           ' hidden file
  270. 'Global Const ATTR_SYSTEM = 4           ' system file
  271. 'Global Const ATTR_VOLUME = 8           ' volume label
  272. 'Global Const ATTR_DIRECTORY = 16       ' MS-DOS directory
  273. 'Global Const ATTR_ARCHIVE = 32         ' archive attribute (not backed up)
  274.  
  275. ' WindowState
  276. Global Const NORMAL = 0    ' 0 - normal
  277. Global Const MINIMIZED = 1 ' 1 - minimized
  278. 'Global Const MAXIMIZED = 2 ' 2 - maximized
  279.  
  280. ' Check Value
  281. Global Const UNCHECKED = 0 ' 0 - unchecked
  282. Global Const CHECKED = 1   ' 1 - checked
  283. 'Global Const GRAYED = 2    ' 2 - unselectable
  284.  
  285. ' Button parameter masks
  286. 'Global Const LEFT_BUTTON = 1
  287. Global Const RIGHT_BUTTON = 2
  288. 'Global Const MIDDLE_BUTTON = 4
  289.  
  290. Sub CopyFile (strSrcFileName As String, strDstFileName As String)
  291.     Dim strMsg As String
  292.     Dim intType As Integer
  293. On Error GoTo CopyErr
  294.     FileCopy strSrcFileName$, strDstFileName$
  295.     Exit Sub
  296. CopyErr:
  297.     Select Case Err
  298.     Case Else
  299.     strMsg$ = "Failed to copy file " & strSrcFileName$ & ". CopyFile Err: " & Err
  300.     intType% = MB_OK Or MB_ICONEXCLAMATION Or MB_APPLMODAL
  301.     MsgBox strMsg$, intType%, APP_CAPTION
  302.     End Select
  303.     Resume Next
  304. End Sub
  305.  
  306. Sub DeleteSwitchTo (DstForm As Form)
  307.     'adjust system menu like a dialog box
  308.     Dim inthMenu As Integer, intResponce As Integer
  309.     inthMenu% = GetSystemMenu(DstForm.hWnd, 0)
  310.     intResponce% = DeleteMenu(inthMenu%, 5, MF_BYPOSITION)
  311.     intResponce% = DeleteMenu(inthMenu%, 6, MF_BYPOSITION)
  312.     intResponce% = DeleteMenu(inthMenu%, 6, MF_BYPOSITION)
  313. End Sub
  314.  
  315. Sub Draw3DButton (DstControl As Control, flag As Integer)
  316.     'Draw PictureBox like 3D button
  317.     'DstControl  : Picture control name
  318.     'flag : True  raised
  319.     '       False lowered
  320.     DstControl.AutoRedraw = True
  321.     DstControl.Cls
  322.     If flag Then
  323.         DstControl.DrawWidth = 1
  324.         DstControl.Line (0, 0)-(DstControl.ScaleWidth - 1, 0), glngColorBTNHIGHLIGHT
  325.         DstControl.Line (0, 1)-(0, DstControl.ScaleHeight - 1), glngColorBTNHIGHLIGHT
  326.         DstControl.Line (DstControl.ScaleWidth - 1, 0)-(DstControl.ScaleWidth - 1, DstControl.ScaleHeight), glngColorBTNTEXT
  327.         DstControl.Line (0, DstControl.ScaleHeight - 1)-(DstControl.ScaleWidth - 1, DstControl.ScaleHeight - 1), glngColorBTNTEXT
  328.         DstControl.Line (1, 1)-(DstControl.ScaleWidth - 2, 1), glngColorBTNFACE
  329.         DstControl.Line (1, 2)-(1, DstControl.ScaleHeight - 2), glngColorBTNFACE
  330.         DstControl.Line (DstControl.ScaleWidth - 2, 1)-(DstControl.ScaleWidth - 2, DstControl.ScaleHeight - 1), glngColorBTNSHADOW
  331.         DstControl.Line (1, DstControl.ScaleHeight - 2)-(DstControl.ScaleWidth - 2, DstControl.ScaleHeight - 2), glngColorBTNSHADOW
  332.     Else
  333.         DstControl.DrawWidth = 1
  334.         DstControl.Line (0, 0)-(DstControl.ScaleWidth - 1, 0), glngColorBTNSHADOW
  335.         DstControl.Line (0, 1)-(0, DstControl.ScaleHeight - 1), glngColorBTNSHADOW
  336.         DstControl.Line (DstControl.ScaleWidth - 1, 0)-(DstControl.ScaleWidth - 1, DstControl.ScaleHeight), glngColorBTNHIGHLIGHT
  337.         DstControl.Line (0, DstControl.ScaleHeight - 1)-(DstControl.ScaleWidth - 1, DstControl.ScaleHeight - 1), glngColorBTNHIGHLIGHT
  338.         DstControl.Line (1, 1)-(DstControl.ScaleWidth - 2, 1), glngColorBTNTEXT
  339.         DstControl.Line (1, 2)-(1, DstControl.ScaleHeight - 2), glngColorBTNTEXT
  340.         DstControl.Line (DstControl.ScaleWidth - 2, 1)-(DstControl.ScaleWidth - 2, DstControl.ScaleHeight - 1), glngColorBTNFACE
  341.         DstControl.Line (1, DstControl.ScaleHeight - 2)-(DstControl.ScaleWidth - 2, DstControl.ScaleHeight - 2), glngColorBTNFACE
  342.     End If
  343.     DstControl.AutoRedraw = False
  344. End Sub
  345.  
  346. Sub Draw3DControl (DstControl As Control)
  347.     'To make is look 3D, lines are drawn on a form with DstControl.
  348.     'Tried to make it look like Ctrl3D.Dll is being used.
  349.     DstControl.Parent.Line (DstControl.Left - 1 * Screen.TwipsPerPixelX, DstControl.Top - 1 * Screen.TwipsPerPixelY)-(DstControl.Left + DstControl.Width, DstControl.Top - 1 * Screen.TwipsPerPixelY), glngColorBTNTEXT&
  350.     DstControl.Parent.Line (DstControl.Left - 1 * Screen.TwipsPerPixelX, DstControl.Top)-(DstControl.Left - 1 * Screen.TwipsPerPixelX, DstControl.Top + DstControl.Height), glngColorBTNTEXT&
  351.     DstControl.Parent.Line (DstControl.Left - 2 * Screen.TwipsPerPixelX, DstControl.Top - 2 * Screen.TwipsPerPixelY)-(DstControl.Left + DstControl.Width + 2 * Screen.TwipsPerPixelX, DstControl.Top - 2 * Screen.TwipsPerPixelY), glngColorBTNSHADOW&
  352.     DstControl.Parent.Line (DstControl.Left - 2 * Screen.TwipsPerPixelX, DstControl.Top - 1 * Screen.TwipsPerPixelY)-(DstControl.Left - 2 * Screen.TwipsPerPixelX, DstControl.Top + DstControl.Height + 1 * Screen.TwipsPerPixelY), glngColorBTNSHADOW&
  353.     DstControl.Parent.Line (DstControl.Left - 2 * Screen.TwipsPerPixelX, DstControl.Top + DstControl.Height + 1 * Screen.TwipsPerPixelY)-(DstControl.Left + DstControl.Width + 2 * Screen.TwipsPerPixelX, DstControl.Top + DstControl.Height + 1 * Screen.TwipsPerPixelY), glngColorBTNHIGHLIGHT&
  354.     DstControl.Parent.Line (DstControl.Left + DstControl.Width + 1 * Screen.TwipsPerPixelX, DstControl.Top - 2 * Screen.TwipsPerPixelY)-(DstControl.Left + DstControl.Width + 1 * Screen.TwipsPerPixelX, DstControl.Top + DstControl.Height + 1 * Screen.TwipsPerPixelY), glngColorBTNHIGHLIGHT&
  355. End Sub
  356.  
  357. Sub Draw3DForm (DstForm As Form)
  358.     'make form look 3D.
  359.     If gintWinVer% <= 310 Then
  360.     'targeted only for Windows 3.1
  361.     DstForm.Line (0, 0)-(DstForm.ScaleWidth, 0), glngColorBTNHIGHLIGHT&
  362.     DstForm.Line (0, 0)-(0, DstForm.ScaleHeight - 1 * Screen.TwipsPerPixelY), glngColorBTNHIGHLIGHT&
  363.     DstForm.Line (0, DstForm.ScaleHeight - 1 * Screen.TwipsPerPixelY)-(DstForm.ScaleWidth, DstForm.ScaleHeight - 1 * Screen.TwipsPerPixelY), glngColorBTNSHADOW&
  364.     DstForm.Line (DstForm.ScaleWidth - 1 * Screen.TwipsPerPixelX, 1 * Screen.TwipsPerPixelY)-(DstForm.ScaleWidth - 1 * Screen.TwipsPerPixelY, DstForm.ScaleHeight - 1 * Screen.TwipsPerPixelX), glngColorBTNSHADOW&
  365.     End If
  366. End Sub
  367.  
  368. Sub Draw3DLine (DstForm As Form, x1%, y1%, x2%, y2%, S%)
  369. 'draw 3D line on form
  370.     If S% Then
  371.     ' raised
  372.     DstForm.Line (x1 + 1 * Screen.TwipsPerPixelX, y1 + 1 * Screen.TwipsPerPixelY)-(x2 + 1 * Screen.TwipsPerPixelX, y2 + 1 * Screen.TwipsPerPixelY), glngColorBTNSHADOW&, B
  373.     DstForm.Line (x1, y1)-(x2, y2), glngColorBTNHIGHLIGHT&, B
  374.     Else
  375.     ' lowered
  376.     DstForm.Line (x1, y1)-(x2, y2), glngColorBTNSHADOW&, B
  377.     DstForm.Line (x1 + 1 * Screen.TwipsPerPixelX, y1 + 1 * Screen.TwipsPerPixelY)-(x2 + 1 * Screen.TwipsPerPixelX, y2 + 1 * Screen.TwipsPerPixelY), glngColorBTNHIGHLIGHT&, B
  378.     End If
  379.     
  380. End Sub
  381.  
  382. '--------------------------------------
  383. 'Draw tool bar
  384. 'DstControl : targeted control(Picture)
  385. '--------------------------------------
  386. Sub Draw3DPanel (DstControl As Control)
  387.     DstControl.AutoRedraw = True
  388.     DstControl.BackColor = glngColorBTNFACE
  389.     'DstControl.Width = DstControl.Parent.ScaleWidth
  390.     DstControl.Line (0, 0)-(DstControl.ScaleWidth, 0), glngColorBTNHIGHLIGHT
  391.     DstControl.Line (0, DstControl.ScaleHeight - 2 * Screen.TwipsPerPixelY)-(DstControl.ScaleWidth, DstControl.ScaleHeight - 2 * Screen.TwipsPerPixelY), glngColorBTNSHADOW
  392.     DstControl.Line (0, DstControl.ScaleHeight - 1 * Screen.TwipsPerPixelY)-(DstControl.ScaleWidth, DstControl.ScaleHeight - 1 * Screen.TwipsPerPixelY), glngColorBTNTEXT
  393.     DstControl.AutoRedraw = False
  394. End Sub
  395.  
  396. Sub DrawBitBlt (DstPic As PictureBox, SrcPic As PictureBox, intSelWidth As Integer, intIndex As Integer)
  397.     Dim intReturnCode As Integer
  398.     DstPic.AutoRedraw = True
  399.     DstPic.Picture = LoadPicture()
  400.     intReturnCode = BitBlt(DstPic.hDC, 0, 0, DstPic.ScaleWidth, DstPic.ScaleHeight, SrcPic.hDC, intSelWidth * intIndex, intSelWidth, SRCAND)
  401.     intReturnCode = BitBlt(DstPic.hDC, 0, 0, DstPic.ScaleWidth, DstPic.ScaleHeight, SrcPic.hDC, intSelWidth * intIndex, 0, SRCINVERT)
  402.     DstPic.Picture = DstPic.Image
  403.     DstPic.AutoRedraw = False
  404. End Sub
  405.  
  406. Function GetCtl3dVersion ()
  407.     'get Ctl3D.DLL version
  408.     Dim intRetCode As Integer, intWorked As Integer
  409.     intRetCode = Ctl3dGetVer()
  410.     intWorked = intRetCode And &HFFFF&
  411.     GetCtl3dVersion = Format((intWorked \ 256) + ((intWorked Mod 256) / 100), "Fixed")
  412. End Function
  413.  
  414. 'get strFileName extension
  415. Function GetFileExt (strFilename As String) As String
  416.     Dim intLoopCount As Integer
  417.     Dim strTmp As String
  418.  
  419.     For intLoopCount% = 1 To Len(strFilename$)
  420.     strTmp$ = Right$(strFilename$, intLoopCount%)
  421.     If InStr(strTmp$, "\") <> 0 Then
  422.         strTmp$ = ""
  423.         Exit For
  424.     End If
  425.     If InStr(strTmp$, ".") <> 0 Then
  426.         strTmp$ = Right$(strTmp$, intLoopCount% - 1)
  427.         Exit For
  428.     End If
  429.     strTmp$ = ""
  430.     Next intLoopCount%
  431.     
  432.     GetFileExt$ = UCase$(strTmp$)
  433.  
  434. End Function
  435.  
  436. Function GetPrivateIni (strSection As String, strKey As String, strDefString As String, strIniFile As String) As String
  437. 'get string from private file
  438.     Dim strBuf          As String * 255
  439.     Dim intReturnCode   As Integer
  440.     intReturnCode% = GetPrivateProfileString(strSection$, strKey$, strDefString$, strBuf$, Len(strBuf$), strIniFile$)
  441.     GetPrivateIni$ = Left(strBuf$, intReturnCode%)
  442. End Function
  443.  
  444. Function GetShortName (strLongPathName As String) As String
  445.     Dim strDriveName As String
  446.     Dim strLastPath As String
  447.     'get drive name
  448.     strDriveName$ = Left$(strLongPathName$, 3)
  449.  
  450.     'get last subdirectory name
  451.     strLastPath$ = Mid$(strLongPathName$, 4)
  452.     Do While InStr(strLastPath$, "\")
  453.     strLastPath$ = Mid$(strLastPath$, InStr(strLastPath$, "\") + 1)
  454.     Loop
  455.     If Len(strDriveName$ & strLastPath$) >= Len(strLongPathName$) Then
  456.     'if file resides in a root directory
  457.     GetShortName$ = strLongPathName$
  458.     Else
  459.     'abbreviate partial path name
  460.     GetShortName = strDriveName$ + "...\" + strLastPath$
  461.     End If
  462. End Function
  463.  
  464. Function GetTmpName (strFirst As String, strExt As String) As String
  465.     Dim intReturnCode   As Integer
  466.     Dim szBuf           As String * 144
  467.     Dim strTmpFile      As String
  468.     Dim strMsg          As String
  469.     Dim intType         As Integer
  470.  
  471.     intReturnCode% = GetTempFileName(0, strFirst, 0, szBuf$)
  472.     strTmpFile$ = Left$(szBuf$, InStr(szBuf$, Chr$(0)) - 1)
  473.     If IsFile(strTmpFile$) = True Then
  474.     Call KillFile(strTmpFile$)
  475.     GetTmpName$ = Left$(strTmpFile$, Len(strTmpFile$) - 3) & strExt
  476.     Else
  477.     strMsg$ = "Unable to create work file."
  478.     strMsg$ = strMsg$ & " Please make sure that there are ample free space in directory specified by TEMP environmental parameter."
  479.     intType% = MB_OK Or MB_ICONSTOP Or MB_APPLMODAL
  480.     MsgBox strMsg$, intType%, APP_CAPTION
  481.     End If
  482. End Function
  483.  
  484. 'return Windows version. If 3.1, return 310
  485. Function GetWindowsVersion ()
  486.     Dim Ver As Long, WinVer As Long
  487.     Ver = GetVersion()
  488.     WinVer = Ver And &HFFFF&
  489.     GetWindowsVersion = (WinVer Mod 256) * 100 + (WinVer \ 256)
  490. End Function
  491.  
  492. '---------------------------
  493. 'check if file exists
  494. 'strFileName : file to search
  495. 'return code:   True   file exists
  496. '               False  file does not exist
  497. '---------------------------
  498. Function IsFile (strFilename As String) As Integer
  499. 'Following is a merit of using the following routine instead of Visual Basic Dir function:
  500. 'True is returned when file exists in the current directory, Windows directory, System
  501. 'directory, or at any of the directory where path is set to.
  502.     Dim udtOpenBuff As tagOFSTRUCT ' information of opened file
  503.     Dim intRetCode As Integer     ' return code
  504.  
  505.     intRetCode = OpenFile(strFilename, udtOpenBuff, OF_EXIST)
  506.     If intRetCode = (-1) Then
  507.     IsFile = False
  508.     Else
  509.     IsFile = True
  510.     End If
  511. End Function
  512.  
  513. Function IsVBRunTime ()
  514.   'Return code: True   if executed as EXE file
  515.   '             False  if executed using VB.EXE
  516.   Dim strMyExeFile As String
  517.   'get full path of application
  518.   strMyExeFile = App.Path
  519.   If Right$(strMyExeFile, 1) <> "\" Then strMyExeFile = strMyExeFile & "\"
  520.   strMyExeFile = strMyExeFile & App.EXEName & ".Exe"
  521.   'check if file exists
  522.   If Dir$(strMyExeFile, 0) = UCase$(App.EXEName & ".Exe") Then
  523.     'check module handle
  524.     If GetModuleHandle(strMyExeFile) <> 0 Then  'exists
  525.       IsVBRunTime = True
  526.       Exit Function
  527.     End If
  528.   End If
  529.   IsVBRunTime = False
  530. End Function
  531.  
  532. 'delete file when error occurs
  533. Sub KillFile (strFilename As String)
  534. Dim strMsg As String
  535. Dim intType As Integer
  536. On Error GoTo KillErr
  537.     If IsFile(strFilename$) = True Then
  538.     Kill strFilename$
  539.     End If
  540.     Exit Sub
  541. KillErr:
  542.     strMsg$ = "Unable to delete file " & strFilename$ & ". KillFile Err: " & Err
  543.     intType% = MB_OK Or MB_ICONEXCLAMATION Or MB_APPLMODAL
  544.     MsgBox strMsg$, intType%, APP_CAPTION
  545.     Resume Next
  546. End Sub
  547.  
  548. 'AddItem gstrTmpLzhFile$ list to DstListBox list box.
  549. 'Return number of items.
  550. 'Set DstListBox.Tag to maximum number of characters of added item.
  551. Function LHAAddArchiveList (DstListBox As Control) As String
  552.     Dim intHarcHnd          As Integer
  553.     Dim tagIndividualinfo   As INDIVIDUALINFO
  554.     Dim intReturnCode       As Integer
  555.     Dim intArcCount         As Integer
  556.     Dim intLoopCount        As Integer
  557.     Dim lngReturnCode       As Long
  558.     Dim strMsg              As String
  559.     Dim intType             As Integer
  560.     Dim strTmp              As String
  561.  
  562.     DstListBox.Clear    'clear list box
  563.     DstListBox.Parent.BackColor = DstListBox.BackColor
  564.     DstListBox.Visible = False
  565.     gintFileMaxLen% = 0
  566.     'total number of files in Lzh archive
  567.     intArcCount% = UnlhaGetFileCount(gstrTmpLzhFile$)
  568.     If intArcCount% > 1024 Then
  569.     'if there are over 1024 files in the archive
  570.     strMsg$ = "There are " & intArcCount% & " files but due to memory and processing speed constraint"
  571.     strMsg$ = strMsg$ & Chr$(10) & " only 1024 files are displayed."
  572.     intType% = MB_OK Or MB_ICONEXCLAMATION
  573.     MsgBox strMsg$, intType%, APP_CAPTION
  574.     intArcCount% = 1024
  575.     End If
  576.  
  577.     DstListBox.Parent.Enabled = False
  578.     Screen.MousePointer = 11  'sand clock
  579.     'Lzh file handle
  580.     intHarcHnd% = UnlhaOpenArchive(DstListBox.Parent.hWnd, gstrTmpLzhFile$, 0)
  581.     
  582.     'get current information on Lzh archive
  583.     intReturnCode% = UnlhaFindFirst(intHarcHnd%, "*.*", tagIndividualinfo)
  584.     'save information to list box
  585.     strTmp$ = LHAMakeList(tagIndividualinfo)
  586.     DstListBox.AddItem strTmp$
  587.     'DstListBox.Tag = LenB(strTmp$)
  588.  
  589.     For intLoopCount% = 1 To intArcCount% - 1
  590.     'get next lzh archive
  591.     intReturnCode% = UnlhaFindNext(intHarcHnd%, tagIndividualinfo)
  592.     'save information to list box
  593.     strTmp$ = LHAMakeList(tagIndividualinfo)
  594.     DstListBox.AddItem strTmp$
  595.     'If DstListBox.Tag < LenB(strTmp$) Then DstListBox.Tag = LenB(strTmp$)
  596.     Next intLoopCount%
  597.     '---------------------------------------
  598.     lngReturnCode& = UnlhaGetArcOriginalSize(intHarcHnd%)
  599.     '---------------------------------------
  600.     'release Lzh archive handle
  601.     intReturnCode% = UnlhaCloseArchive(intHarcHnd%)
  602.     
  603.     'set return code
  604.     LHAAddArchiveList$ = "Total Files: " & UnlhaGetFileCount(gstrTmpLzhFile$) & " (" & Format$(lngReturnCode&, "#,###") & "bytes)"
  605.     DstListBox.Visible = True
  606.     DstListBox.Parent.Enabled = True
  607.     Screen.MousePointer = 0  'current value
  608. End Function
  609.  
  610. 'check UNLHA.DLL supported functions
  611. Function LHACheckFunction () As String
  612.     Dim strTmp As String
  613.     strTmp$ = "UNLHA.DLL Version " & Format$((UnlhaGetVersion() / 100), "Fixed")
  614.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_VERSION = " & UnlhaQueryFunctionList(ISARC_GET_VERSION)
  615.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_CURSOR_INTERVAL = " & UnlhaQueryFunctionList(ISARC_GET_CURSOR_INTERVAL)
  616.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_SET_CURSOR_INTERVAL = " & UnlhaQueryFunctionList(ISARC_SET_CURSOR_INTERVAL)
  617.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_BACK_GROUND_MODE = " & UnlhaQueryFunctionList(ISARC_GET_BACK_GROUND_MODE)
  618.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_SET_BACK_GROUND_MODE = " & UnlhaQueryFunctionList(ISARC_SET_BACK_GROUND_MODE)
  619.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_BACK_GROUND_MODE = " & UnlhaQueryFunctionList(ISARC_GET_BACK_GROUND_MODE)
  620.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_SET_BACK_GROUND_MODE = " & UnlhaQueryFunctionList(ISARC_SET_BACK_GROUND_MODE)
  621.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_CURSOR_MODE = " & UnlhaQueryFunctionList(ISARC_GET_CURSOR_MODE)
  622.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_SET_CURSOR_MODE = " & UnlhaQueryFunctionList(ISARC_SET_CURSOR_MODE)
  623.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_RUNNING = " & UnlhaQueryFunctionList(ISARC_GET_RUNNING)
  624.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_CHECK_ARCHIVE = " & UnlhaQueryFunctionList(ISARC_CHECK_ARCHIVE)
  625.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_CONFIG_DIALOG = " & UnlhaQueryFunctionList(ISARC_CONFIG_DIALOG)
  626.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_FILE_COUNT = " & UnlhaQueryFunctionList(ISARC_GET_FILE_COUNT)
  627.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_QUERY_FUNCTION_LIST = " & UnlhaQueryFunctionList(ISARC_QUERY_FUNCTION_LIST)
  628.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_HOUT = " & UnlhaQueryFunctionList(ISARC_HOUT)
  629.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_STRUCTOUT = " & UnlhaQueryFunctionList(ISARC_STRUCTOUT)
  630.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_FILE_INFO = " & UnlhaQueryFunctionList(ISARC_GET_ARC_FILE_INFO)
  631.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_OPEN_ARCHIVE = " & UnlhaQueryFunctionList(ISARC_OPEN_ARCHIVE)
  632.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_CLOSE_ARCHIVE = " & UnlhaQueryFunctionList(ISARC_CLOSE_ARCHIVE)
  633.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_FIND_FIRST = " & UnlhaQueryFunctionList(ISARC_FIND_FIRST)
  634.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_FIND_NEXT = " & UnlhaQueryFunctionList(ISARC_FIND_NEXT)
  635.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_EXTRACT = " & UnlhaQueryFunctionList(ISARC_EXTRACT)
  636.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_ADD = " & UnlhaQueryFunctionList(ISARC_ADD)
  637.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_MOVE = " & UnlhaQueryFunctionList(ISARC_MOVE)
  638.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_DELETE = " & UnlhaQueryFunctionList(ISARC_DELETE)
  639.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_FILE_NAME = " & UnlhaQueryFunctionList(ISARC_GET_ARC_FILE_NAME)
  640.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_FILE_SIZE = " & UnlhaQueryFunctionList(ISARC_GET_ARC_FILE_SIZE)
  641.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_ORIGINAL_SIZE = " & UnlhaQueryFunctionList(ISARC_GET_ARC_ORIGINAL_SIZE)
  642.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_COMPRESSED_SIZE = " & UnlhaQueryFunctionList(ISARC_GET_ARC_COMPRESSED_SIZE)
  643.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_RATIO = " & UnlhaQueryFunctionList(ISARC_GET_ARC_RATIO)
  644.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_DATE = " & UnlhaQueryFunctionList(ISARC_GET_ARC_DATE)
  645.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_TIME = " & UnlhaQueryFunctionList(ISARC_GET_ARC_TIME)
  646.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_OS_TYPE = " & UnlhaQueryFunctionList(ISARC_GET_ARC_OS_TYPE)
  647.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ARC_IS_SFX_FILE = " & UnlhaQueryFunctionList(ISARC_GET_ARC_IS_SFX_FILE)
  648.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_FILE_NAME = " & UnlhaQueryFunctionList(ISARC_GET_FILE_NAME)
  649.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ORIGINAL_SIZE = " & UnlhaQueryFunctionList(ISARC_GET_ORIGINAL_SIZE)
  650.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_COMPRESSED_SIZE = " & UnlhaQueryFunctionList(ISARC_GET_COMPRESSED_SIZE)
  651.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_RATIO = " & UnlhaQueryFunctionList(ISARC_GET_RATIO)
  652.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_DATE = " & UnlhaQueryFunctionList(ISARC_GET_DATE)
  653.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_TIME = " & UnlhaQueryFunctionList(ISARC_GET_TIME)
  654.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_CRC = " & UnlhaQueryFunctionList(ISARC_GET_CRC)
  655.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_ATTRIBUTE = " & UnlhaQueryFunctionList(ISARC_GET_ATTRIBUTE)
  656.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_OS_TYPE = " & UnlhaQueryFunctionList(ISARC_GET_OS_TYPE)
  657.     strTmp$ = strTmp$ & Chr$(13) & Chr$(10) & "ISARC_GET_METHOD = " & UnlhaQueryFunctionList(ISARC_GET_METHOD)
  658.     LHACheckFunction$ = strTmp$ & Chr$(13) & Chr$(10)
  659. End Function
  660.  
  661. 'delete file in Lzh archive
  662. Function LHADelete (strFilename As String) As Integer
  663.     Dim intReturnCode   As Integer
  664.     Dim strCommandLine  As String
  665.     Dim strBuffer       As String * 10000
  666.     Dim strMsg          As String
  667.     Dim intType         As Integer
  668.     Dim strOption       As String
  669.     strMsg$ = "Delete file " & strFilename$
  670.     intType% = MB_YESNOCANCEL Or MB_ICONQUESTION Or MB_DEFBUTTON1
  671.     Select Case MsgBox(strMsg$, intType%, APP_CAPTION)
  672.     Case IDYES
  673.     strOption$ = "-n "    'do not display extraction progress dialog box
  674.     strCommandLine$ = "d " & strOption$ & gstrTmpLzhFile$ & " " & strFilename$
  675.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  676.     LHADelete% = LHAErrCode(intReturnCode%)
  677.     gintbSaveFlag% = True
  678.     Case IDNO
  679.     LHADelete% = 0
  680.     Case IDCANCEL
  681.     LHADelete% = (-1)
  682.     End Select
  683.     
  684. End Function
  685.  
  686. Function LHAErrCode (intReturnCode As Integer) As Integer
  687.     Dim strMsg  As String
  688.     Dim intType As Integer
  689.     
  690.     Select Case intReturnCode%
  691.     Case 0  'normal
  692.     LHAErrCode% = 0
  693.     Exit Function
  694.     Case ERROR_DISK_SPACE           'Not enough disk space to extract file
  695.     strMsg$ = "Not enough disk space to extract file."
  696.     Case ERROR_READ_ONLY            'Read only file already exists
  697.     strMsg$ = "Read only file already exists."
  698.     Case ERROR_USER_SKIP            'Skip extraction upon user request
  699.     strMsg$ = "Skip extraction upon user request."
  700.     Case ERROR_FILE_CRC             'Archive file CRC file error
  701.     strMsg$ = "Archive file CRC file error."
  702.     Case ERROR_FILE_OPEN            'Unable to open file during extraction
  703.     strMsg$ = "Unable to open file during extraction."
  704.     Case ERROR_MORE_FRESH           'More current file already exists
  705.     strMsg$ = "More current file already exists."
  706.     Case ERROR_NOT_EXIST            'File does not exists at specified directory
  707.     strMsg$ = "File does not exists at specified directory."
  708.     Case ERROR_DIRECTORY            'Unable to make directory
  709.     strMsg$ = "Unable to make directory."
  710.     Case ERROR_CANNOT_WRITE         'Write error while extracting file
  711.     strMsg$ = "Write error while extracting file."
  712.     Case ERROR_HUFFMAN_CODE         'Broken Huffman code in LZH file
  713.     strMsg$ = "Broken Huffman code in LZH file."
  714.     Case ERROR_COMMENT_HEADER       'Broken comment header in LZH file
  715.     strMsg$ = "Broken comment header in LZH file."
  716.     Case ERROR_HEADER_CRC           'Header CRC error in LZH file
  717.     strMsg$ = "Header CRC error in LZH file."
  718.     Case ERROR_HEADER_BROKEN        'Broken header in LZH file
  719.     strMsg$ = "Broken header in LZH file."
  720.     Case ERROR_ARC_FILE_OPEN        'Unable to open LZH file
  721.     strMsg$ = "Unable to open LZH file."
  722.     Case ERROR_NOT_ARC_FILE         'Specified archive file is not LZH file
  723.     strMsg$ = "Specified archive file is not LZH file."
  724.     Case ERROR_CANNOT_READ          'Read error when reading LZH file
  725.     strMsg$ = "Read error when reading LZH file."
  726.     Case ERROR_FILE_STYLE           'Specified archive file is not LZH file
  727.     strMsg$ = "Specified archive file is not LZH file."
  728.     Case ERROR_COMMAND_NAME         'Illegal command
  729.     strMsg$ = "Illegal command."
  730.     Case ERROR_MORE_HEAP_MEMORY     'Not enough heap memory for work
  731.     strMsg$ = "Not enough heap memory for work."
  732.     Case ERROR_ENOUGH_MEMORY        'Not enough global memory
  733.     strMsg$ = "Not enough global memory."
  734.     Case ERROR_ALREADY_RUNNING      'UNLHA.DLL already running from different process
  735.     strMsg$ = "UNLHA.DLL already running from different process."
  736.     Case ERROR_USER_CANCEL          'Extraction terminated by user's request
  737.     strMsg$ = "Extraction terminated by user's request."
  738.     Case ERROR_HARC_ISNOT_OPENED    'UnlhaFindFirst() called before UnlhaOpenArchive() called to associate file to a handle
  739.     strMsg$ = "UnlhaFindFirst() called before UnlhaOpenArchive() called to associate file to a handle."
  740.     Case ERROR_NOT_SEARCH_MODE      'UnlhaFindNext() called before UnlhaFindFirst() called or either function called before UnlhaGetFileName() called
  741.     strMsg$ = "UnlhaFindNext() called before UnlhaFindFirst() called or either function called before UnlhaGetFileName() called."
  742.     Case ERROR_NOT_SUPPORT          'API not supported by UNLHA.DLL called
  743.     strMsg$ = "API not supported by UNLHA.DLL called."
  744.     Case ERROR_TIME_STAMP           'Illegal date/time format
  745.     strMsg$ = "Illegal date/time format."
  746.     Case ERROR_TMP_OPEN             'Unable to open work file
  747.     strMsg$ = "Unable to open work file."
  748.     Case ERROR_LONG_FILE_NAME       'Directory path too long
  749.     strMsg$ = "Directory path too long."
  750.     Case ERROR_ARC_READ_ONLY        'Unable to process write only archive file
  751.     strMsg$ = "Unable to process write only archive file."
  752.     Case ERROR_SAME_NAME_FILE       'File already exits in the archive file
  753.     strMsg$ = "File already exits in the archive file."
  754.     Case ERROR_NOT_FIND_ARC_FILE    'Unable to find LZH file at specified directory
  755.     strMsg$ = "Unable to find LZH file at specified directory."
  756.     Case Else
  757.     strMsg$ = "Unrecognizable error!"
  758.     End Select
  759.     strMsg$ = strMsg$ & Chr$(13) & "Unable to extract file. Stopping file extraction. Err:" & intReturnCode%
  760.     intType% = MB_OK Or MB_ICONEXCLAMATION
  761.     LHAErrCode% = intReturnCode%
  762.     MsgBox strMsg$, intType%, APP_CAPTION
  763.  
  764. End Function
  765.  
  766. 'Execute after associating strFileName
  767. 'WinExec is used so allow concurrent execution
  768. Sub LHAExecuteFile (strFilename As String)
  769.     Dim intReturnCode       As Integer
  770.     Dim strBuffer           As String * 128
  771.     Dim strExecuteFile      As String
  772.     Dim strOption           As String
  773.     Dim strMsg              As String       'for MsgBox
  774.     Dim intType             As Integer      'for MsgBox
  775.     Dim intModuleCount      As Integer      'Module count of running programs
  776.     Dim intTmpModuleCount   As Integer      'Temporary module count
  777.  
  778.     gstrUnpackDir$ = Left$(gstrTmpLzhFile$, InStr(gstrTmpLzhFile$, "\~wrk"))
  779.     If IsFile(gstrUnpackDir$ & strFilename$) = True Then
  780.     'File to be extracted is in the work directory
  781.     strMsg$ = "File " & strFilename$ & " not found in work directory " & gstrUnpackDir$
  782.     strMsg$ = strMsg$ & Chr$(10) & "Overwrite?"
  783.     intType% = MB_OKCANCEL Or MB_ICONEXCLAMATION Or MB_DEFBUTTON2
  784.     Select Case MsgBox(strMsg$, intType%, APP_CAPTION)
  785.     Case IDCANCEL
  786.         Exit Sub
  787.     End Select
  788.     End If
  789.     strOption$ = "-n"   'Do not display extraction progress
  790.     'Extract using Dir information?
  791.     If gintbDirFlag% = True Then
  792.     strOption$ = strOption$ & " -x"
  793.     End If
  794.     'Overwrite existing file?
  795.     If gintbOverWriteFalg% = True Then
  796.     strOption$ = strOption$ & " -c"
  797.     End If
  798.     'Extract file
  799.     intReturnCode% = LHAUnpack(strFilename$, strOption$)
  800.     If intReturnCode% <> 0 Then
  801.     'Error extracting file
  802.     Exit Sub
  803.     End If
  804.     'Get associated information
  805.     intReturnCode% = FindExecutable(gstrUnpackDir$ & strFilename$, CurDir$, strBuffer$)
  806.     Select Case intReturnCode%
  807.     Case 2      'File not found
  808.     If IsFile(gstrUnpackDir$ & Left$(strFilename$, 8)) = True Then
  809.     'Files with long file name and without file extension
  810.     'UNLHA.DLL uses only the first 8 characters of a file name.
  811.         Call KillFile(gstrUnpackDir$ & Left$(strFilename$, 8))
  812.     End If
  813.     Case 0 To 32    'Display error check?
  814.     strMsg$ = "Unable to find execution file. FindExecutable Err: " & intReturnCode%
  815.     intType% = MB_OK Or MB_ICONEXCLAMATION Or MB_APPLMODAL
  816.     MsgBox strMsg$, intType%, APP_CAPTION
  817.     Call KillFile(gstrUnpackDir$ & strFilename$)
  818.     Exit Sub
  819.     End Select
  820.     strExecuteFile$ = Left$(strBuffer$, InStr(strBuffer$, Chr$(0)) - 1)
  821.     
  822.     If strExecuteFile$ = "" Then
  823.     'If no associated information, it could be an executable file
  824.     Select Case GetFileExt(strFilename$)
  825.     Case "PIF"
  826.     Case "EXE"
  827.     Case "COM"
  828.     Case "BAT"
  829.     Case Else
  830.         'If no associated file and if not executable file
  831.         'delete extracted file
  832.         Call KillFile(gstrUnpackDir$ & strFilename$)
  833.         Exit Sub
  834.     End Select
  835.     End If
  836.     'Execute file
  837.     intReturnCode% = WinExec(strExecuteFile$ & " " & gstrUnpackDir$ & strFilename$, SW_RESTORE)
  838.     If intReturnCode% <= 32 Then
  839.     strMsg$ = "Unable to execute file. WinExec Err: " & intReturnCode%
  840.     intType% = MB_OK Or MB_ICONEXCLAMATION Or MB_APPLMODAL
  841.     MsgBox strMsg$, intType%, APP_CAPTION
  842.     'Delete executed file
  843.     Call KillFile(gstrUnpackDir$ & strFilename$)
  844.     Exit Sub
  845.     End If
  846.     intModuleCount% = GetModuleUsage(intReturnCode%)
  847.     intTmpModuleCount% = intModuleCount%
  848.     gintWorkCount% = gintWorkCount% + 1     'Number of running programs
  849.     Do While intTmpModuleCount% = intModuleCount%
  850.     'Loop referring to number of executing modules
  851.     intModuleCount% = GetModuleUsage(intReturnCode%)
  852.     DoEvents
  853.     Loop
  854.     'Delete extracted file
  855.     Call KillFile(gstrUnpackDir$ & strFilename$)
  856.     gintWorkCount% = gintWorkCount% - 1     'Number of running programs
  857. End Sub
  858.  
  859. Function LHAGetFileInfo (DstForm As Form, strFilename As String) As String
  860.     Dim intHarcHnd          As Integer
  861.     Dim tagIndividualinfo   As INDIVIDUALINFO
  862.     Dim intReturnCode       As Integer
  863.     Dim strInfo              As String
  864.  
  865.     intHarcHnd% = UnlhaOpenArchive(DstForm.hWnd, gstrTmpLzhFile, 0)
  866.     intReturnCode% = UnlhaFindFirst(intHarcHnd%, strFilename$, tagIndividualinfo)
  867.     intReturnCode% = UnlhaCloseArchive(intHarcHnd%)
  868.     strInfo$ = "File Name:" & Chr$(9) & Chr$(9) & Left$(tagIndividualinfo.szFileName, InStr(tagIndividualinfo.szFileName, Chr$(0)) - 1)
  869.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "File Size:" & Chr$(9) & tagIndividualinfo.dwOriginalSize & "Bytes"
  870.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "Archive Size▐:" & Chr$(9) & tagIndividualinfo.dwCompressedSize & "Bytes"
  871.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "Comp. Ratio:" & Chr$(9) & Chr$(9) & tagIndividualinfo.wRatio / 10 & "%"
  872.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "Date:" & Chr$(9) & Chr$(9) & (((tagIndividualinfo.wDate And &HFE00&) / 2 ^ 9) + 1980) & "-" & Format$(((tagIndividualinfo.wDate And &H1E0) / 2 ^ 5), "00") & "-" & Format$((tagIndividualinfo.wDate And &H1F), "00")
  873.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "Time:" & Chr$(9) & Chr$(9) & Format$(((tagIndividualinfo.wTime And &HF800&) / 2 ^ 11), "00") & ":" & Format$(((tagIndividualinfo.wTime And &H7E0) / 2 ^ 5), "00") & ":" & Format$(((tagIndividualinfo.wTime And &H1F) * 2), "00")
  874.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "CRC:" & Chr$(9) & Chr$(9) & Hex$(tagIndividualinfo.dwCRC)
  875.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "File Attr:" & Chr$(9) & Left$(tagIndividualinfo.szAttribute, 4)
  876.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "Comp. Type:" & Chr$(9) & Chr$(9) & Left$(tagIndividualinfo.szMode, 5)
  877.     strInfo$ = strInfo$ & Chr$(13) & Chr$(10) & "OS:" & Chr$(9) & Chr$(9) & LHAGetOSType(tagIndividualinfo.uOSType)
  878.     LHAGetFileInfo$ = strInfo$
  879. End Function
  880.  
  881. Function LHAGetOSType (intType As Integer) As String
  882.     Select Case intType%
  883.     Case 0  'MS-DOS
  884.     LHAGetOSType$ = "MS-DOS"
  885.     Case 2  'UNIX
  886.     LHAGetOSType$ = "UNIX"
  887.     Case 4  'MAC-OS
  888.     LHAGetOSType$ = "MAC-OS"
  889.     Case 5  'OS/2
  890.     LHAGetOSType$ = "OS/2"
  891.     Case 10 'others
  892.     LHAGetOSType$ = "Others"
  893.     Case 11 'OS9
  894.     LHAGetOSType$ = "OS9"
  895.     Case 12 'OS/68K
  896.     LHAGetOSType$ = "OS/68K"
  897.     Case 13 'OS/386
  898.     LHAGetOSType$ = "OS/386"
  899.     Case 14 'HUMAN
  900.     LHAGetOSType$ = "HUMAN"
  901.     Case 15 'CP/M
  902.     LHAGetOSType$ = "CP/M"
  903.     Case 16 'FLEX
  904.     LHAGetOSType$ = "FLEX"
  905.     Case 17 'Runser
  906.     LHAGetOSType$ = "Runser"
  907.     Case -1 'Error
  908.     LHAGetOSType$ = "Error"
  909.     Case Else
  910.     LHAGetOSType$ = "Undefined"
  911.     End Select
  912. End Function
  913.  
  914. 'set text string from INDIVIDUALINFO structure in comparable format as "LHA l "
  915. 'SOme information may not be got depending on the display option.
  916. Function LHAMakeList (tagIndividualinfo As INDIVIDUALINFO) As String
  917.     Dim strTmp          As String
  918.     Dim strArcList      As String
  919.     Dim strWork         As String   'set to first directory starting with "/" in directory information present
  920.     Dim intLoopCount    As Integer
  921.     Dim intTmpFileLen   As Integer
  922.  
  923.     'get file name
  924.     strTmp$ = Left$(tagIndividualinfo.szFileName, InStr(tagIndividualinfo.szFileName, Chr$(0)) - 1)
  925.     'if directory information is included
  926.     strArcList$ = Space$(2) & strTmp$ & Chr$(9)
  927.     'set gintFilemaxLen% (global variable) to maximum file name length
  928.     If gintFileMaxLen% < Len(strTmp$) Then
  929.     gintFileMaxLen% = Len(strTmp$)
  930.     End If
  931.  
  932.     If Mid$(gstrListViewOption$, 1, 1) = "1" Then
  933.     'size
  934.     strTmp$ = CStr(tagIndividualinfo.dwOriginalSize)
  935.     strArcList$ = strArcList$ & Space$(8 - Len(strTmp$)) & strTmp$ & Space$(2)
  936.     End If
  937.     If Mid$(gstrListViewOption$, 2, 1) = "1" Then
  938.     'archive size
  939.     strTmp$ = CStr(tagIndividualinfo.dwCompressedSize)
  940.     strArcList$ = strArcList$ & Space$(8 - Len(strTmp$)) & strTmp$ & Space$(1)
  941.     End If
  942.     If Mid$(gstrListViewOption$, 3, 1) = "1" Then
  943.     'compression rate
  944.     strTmp$ = Format$((tagIndividualinfo.wRatio / 10), "0.0") & "%"
  945.     strArcList$ = strArcList$ & Space$(6 - Len(strTmp$)) & strTmp$ & Space$(1)
  946.     End If
  947.     If Mid$(gstrListViewOption$, 4, 1) = "1" Then
  948.     'date
  949.     strTmp$ = (((tagIndividualinfo.wDate And &HFE00&) / 2 ^ 9) + 80) & "-" & Format$(((tagIndividualinfo.wDate And &H1E0) / 2 ^ 5), "00") & "-" & Format$((tagIndividualinfo.wDate And &H1F), "00")
  950.     strArcList$ = strArcList$ & strTmp$ & Space$(1)
  951.     End If
  952.     If Mid$(gstrListViewOption$, 5, 1) = "1" Then
  953.     'time
  954.     strTmp$ = Format$(((tagIndividualinfo.wTime And &HF800&) / 2 ^ 11), "00") & ":" & Format$(((tagIndividualinfo.wTime And &H7E0) / 2 ^ 5), "00") & ":" & Format$(((tagIndividualinfo.wTime And &H1F) * 2), "00")
  955.     strArcList$ = strArcList$ & strTmp$ & Space$(1)
  956.     End If
  957.     If Mid$(gstrListViewOption$, 6, 1) = "1" Then
  958.     'attributes
  959.     strTmp$ = LCase$(Left$(tagIndividualinfo.szAttribute, 4))
  960.     strArcList$ = strArcList$ & strTmp$ & Space$(1)
  961.     End If
  962.     If Mid$(gstrListViewOption$, 7, 1) = "1" Then
  963.     'compression method
  964.     strTmp$ = Left$(tagIndividualinfo.szMode, 5)
  965.     strArcList$ = strArcList$ & LCase$(strTmp$) & Space$(1)
  966.     End If
  967.     If Mid$(gstrListViewOption$, 8, 1) = "1" Then
  968.     'CRC
  969.     strTmp$ = Hex$(tagIndividualinfo.dwCRC)
  970.     'fill with "0" to always make it 4 digits
  971.     strArcList$ = strArcList$ & String$(4 - Len(strTmp$), "0") & strTmp$
  972.     End If
  973.     LHAMakeList$ = RTrim$(strArcList$) & Space$(2)
  974. End Function
  975.  
  976. 'compression
  977. Function LHAPack (strFilename As String) As Integer
  978.     Dim intReturnCode   As Integer
  979.     Dim strCommandLine  As String
  980.     Dim strBuffer       As String * 10000
  981.     Dim strOption       As String
  982.     strOption$ = "-n "    'do not display extraction progress status
  983.     strCommandLine$ = "a " & strOption$ & gstrTmpLzhFile$ & " " & strFilename$
  984.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  985.     LHAPack = LHAErrCode(intReturnCode%)
  986.     gintbSaveFlag% = True
  987. End Function
  988.  
  989. Function LHAPackMove (strFilename As String) As Integer
  990.     Dim intReturnCode   As Integer
  991.     Dim strCommandLine  As String
  992.     Dim strBuffer       As String * 10000
  993.     strCommandLine$ = "m " & gstrTmpLzhFile$ & " " & strFilename$
  994.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  995.     LHAPackMove% = LHAErrCode(intReturnCode%)
  996. End Function
  997.  
  998. Sub LHASetMode ()
  999.     Dim intReturnCode As Integer
  1000.     intReturnCode% = UnlhaSetBackGroundMode(0)  'run in background mode
  1001.     intReturnCode% = UnlhaSetCursorMode(1)      'display cursor
  1002. End Sub
  1003.  
  1004. Function LHASFX () As Integer
  1005.     Dim intReturnCode   As Integer
  1006.     Dim strCommandLine  As String
  1007.     Dim strBuffer       As String * 10000
  1008.     Dim strOption       As String
  1009.     strCommandLine$ = "s -jw -x1 -n " & gstrTmpLzhFile$
  1010.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  1011.     LHASFX% = LHAErrCode(intReturnCode%)
  1012.     gintbSaveFlag% = True
  1013. End Function
  1014.  
  1015. Function LHATest (strFilename As String) As Integer
  1016.     Dim intReturnCode   As Integer
  1017.     Dim strCommandLine  As String
  1018.     Dim strBuffer       As String * 10000
  1019.     Dim strOption       As String
  1020.     strOption$ = " -n "    'do not display extraction progress status
  1021.     strCommandLine$ = "t " & strOption$ & gstrTmpLzhFile$ & " " & strFilename$
  1022.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  1023.     LHATest% = LHAErrCode(intReturnCode%)
  1024. End Function
  1025.  
  1026. 'extract
  1027. '   strFileName$ : name of file to extract
  1028. '   strOption$   : extraction options
  1029. Function LHAUnpack (strFilename As String, strOption As String) As Integer
  1030.     Dim intReturnCode   As Integer
  1031.     Dim strCommandLine  As String
  1032.     Dim strBuffer       As String * 10000
  1033.     If Len(strOption$) <> 0 Then strOption$ = strOption$ & " "
  1034.     strCommandLine$ = "e " & strOption$ & gstrTmpLzhFile$ & " " & gstrUnpackDir$ & " " & strFilename$
  1035.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  1036.     LHAUnpack% = LHAErrCode(intReturnCode%)
  1037. End Function
  1038.  
  1039. Function LHAViewFile (strFilename As String) As String
  1040.     Dim intReturnCode   As Integer
  1041.     Dim strCommandLine  As String
  1042.     Dim strBuffer       As String * 10000
  1043.     Dim strOption       As String
  1044.     Dim strWork         As String
  1045.     strOption$ = "-n "    'do not display extraction progress status
  1046.     strCommandLine$ = "p " & strOption$ & gstrTmpLzhFile$ & " " & strFilename$
  1047.     intReturnCode% = Unlha(strCommandLine$, strBuffer$, Len(strBuffer$))
  1048.     If LHAErrCode(intReturnCode%) <> 0 Then Exit Function
  1049.     strWork$ = Left$(strBuffer, InStr(strBuffer$, Chr$(0)) - 1)
  1050.     If Len(strWork$) >= 9999 Then
  1051.     LHAViewFile$ = strWork$ & Chr$(13) & Chr$(10) & "[More...]"
  1052.     Else
  1053.     LHAViewFile$ = strWork$ & Chr$(13) & Chr$(10) & "[EOF]"
  1054.     End If
  1055. End Function
  1056.  
  1057. Sub Main ()
  1058.     Dim strMsg  As String
  1059.     Dim intType As Integer
  1060.  
  1061.     gintWinVer% = GetWindowsVersion()
  1062.     'check Windows version
  1063.     If gintWinVer% < 310 Then
  1064.     strMsg$ = "Windows 3.1 necessary to run " & APP_CAPTION & "."
  1065.     intType% = MB_OK Or MB_ICONEXCLAMATION
  1066.     MsgBox strMsg$, intType%, APP_CAPTION
  1067.     End
  1068.     End If
  1069.     'check if UNLHA.DLL exists
  1070.     If IsFile("UNLHA.DLL") = False Then
  1071.     strMsg$ = "File UNLHA.DLL necessary to run " & APP_CAPTION & "."
  1072.     intType% = MB_OK Or MB_ICONEXCLAMATION
  1073.     MsgBox strMsg$, intType%, APP_CAPTION
  1074.     End
  1075.     End If
  1076.     'check if minimum necessary memory is free
  1077.     If GetFreeSystemResources(GFSR_SYSTEMRESOURCES) < 20 Then    'not enough memory
  1078.     strMsg$ = "Not enough system resource" & Chr$(13)
  1079.     strMsg$ = strMsg$ & "Please end other applications and re-execute the program again."
  1080.     intType% = MB_OK Or MB_ICONSTOP
  1081.     MsgBox strMsg$, intType%, APP_CAPTION
  1082.     End
  1083.     End If
  1084.     'initialize UNLHA.DLL
  1085.     Call LHASetMode
  1086.     'check help file
  1087.     gstrHelpFile$ = App.EXEName & ".HLP"
  1088.     If IsFile(gstrHelpFile$) = True Then
  1089.     App.HelpFile = gstrHelpFile$
  1090.     Else
  1091.     gstrHelpFile$ = ""
  1092.     End If
  1093.     'get windows system color
  1094.     Call SetSystemColorValue
  1095.     'get size of windows
  1096.     Call SetSystemMetricsValue
  1097.     'initialize variables
  1098.     gintWorkCount% = 0
  1099.     
  1100.     'load main form
  1101.     Load frmArchive
  1102. End Sub
  1103.  
  1104. '---------------------------------------------------
  1105. 'center new form to that of old form
  1106. 'DstForm : form
  1107. '---------------------------------------------------
  1108. Sub SetChildWindowPos (ParentForm As Form, DstForm As Form)
  1109.     Dim intTmpLeft As Integer, intTmpTop As Integer
  1110.     'calculate horizontal position
  1111.     intTmpLeft = ParentForm.Left + ParentForm.Width \ 2 - DstForm.Width \ 2
  1112.     If intTmpLeft < 0 Then    'if past left edge of screen
  1113.     intTmpLeft = 0
  1114.     ElseIf intTmpLeft > Screen.Width - DstForm.Width Then
  1115.                   'if past right edge of screen
  1116.     intTmpLeft = Screen.Width - DstForm.Width
  1117.     End If
  1118.     'calculate vertical position
  1119.     intTmpTop = ParentForm.Top + ParentForm.Height \ 2 - DstForm.Height \ 2
  1120.     If intTmpTop < 0 Then     'if past top edge of screen
  1121.     intTmpTop = 0
  1122.     ElseIf intTmpTop > Screen.Height - DstForm.Height Then
  1123.                   'if past bottom edge of screen
  1124.     intTmpTop = Screen.Height - DstForm.Height
  1125.     End If
  1126.     DstForm.Left = intTmpLeft
  1127.     DstForm.Top = intTmpTop
  1128. End Sub
  1129.  
  1130. Sub SetCTL3DDLL (DstForm As Form, intFlag As Integer)
  1131. 'Call CTL3D.DLL to create 3D effect.
  1132. 'Use instance handle to set CTL3D.DLL as a subclass.
  1133. 'Only use if EXE because if in VB mode, handle might not be
  1134. 'released when program terminates.
  1135.     Dim intRetCode As Integer
  1136.     Dim intInstanceHandle As Integer
  1137.  
  1138.     If gintWinVer% > 310 Then Exit Sub              'quit if Windows above v3.1
  1139.     If IsVBRunTime() = False Then Exit Sub          'quit if VB.EXE executing
  1140.     If IsFile("CTL3D.DLL") = False Then Exit Sub    'quit if CTL3D.DLL not found
  1141.     If GetCtl3dVersion() < 2.01 Then Exit Sub       'if before ver 2.01 quit. (there is a bug)
  1142.     
  1143.     intInstanceHandle% = GetWindowWord(DstForm.hWnd, GWW_HINSTANCE)
  1144.     
  1145.     Select Case intFlag%
  1146.     Case True    'during Form load
  1147.     intRetCode% = Ctl3dRegister(intInstanceHandle%)
  1148.     intRetCode% = Ctl3dAutoSubClass(intInstanceHandle%)
  1149.     Case False   'during Form unload
  1150.     intRetCode% = Ctl3dUnregister(intInstanceHandle%)
  1151.     End Select
  1152. End Sub
  1153.  
  1154. Sub SetLstBoxAllSelect (DstListBox As ListBox, intbFlag As Integer)
  1155.     'Select all DstListBox list boxes
  1156.     Dim lngReturnCode As Long
  1157.     Select Case intbFlag%
  1158.     Case True
  1159.     lngReturnCode& = SendMessage(DstListBox.hWnd, LB_SETSEL, ByVal 1&, ByVal -1&)
  1160.     Case False
  1161.     lngReturnCode& = SendMessage(DstListBox.hWnd, LB_SETSEL, ByVal 0&, ByVal -1&)
  1162.     End Select
  1163. End Sub
  1164.  
  1165. Sub SetLstBoxHScrollBar (DstListBox As Control, intListWidth As Integer)
  1166.     Dim lngReturnCode      As Long
  1167.     'SendMessage to list box to display horizontal scroll bar
  1168.     lngReturnCode = SendMessage(DstListBox.hWnd, LB_SETHORIZONTALEXTENT, intListWidth%, 0&)
  1169.     DstListBox.Refresh
  1170. End Sub
  1171.  
  1172. Sub SetSystemColorValue ()
  1173.     glngColorBTNHIGHLIGHT = GetSysColor(COLOR_BTNHIGHLIGHT)
  1174.     glngColorBTNTEXT = GetSysColor(COLOR_BTNTEXT)
  1175.     glngColorBTNSHADOW = GetSysColor(COLOR_BTNSHADOW)
  1176.     glngColorBTNFACE = GetSysColor(COLOR_BTNFACE)
  1177.     glngColorWINDOW = GetSysColor(COLOR_WINDOW)
  1178. End Sub
  1179.  
  1180. Sub SetSystemMetricsValue ()
  1181.     
  1182.     gintCXBORDER% = GetSystemMetrics(SM_CXBORDER)
  1183.     gintCYBORDER% = GetSystemMetrics(SM_CYBORDER)
  1184.     gintCYCAPTION% = GetSystemMetrics(SM_CYCAPTION)
  1185.     gintCXDLGFRAME% = GetSystemMetrics(SM_CXDLGFRAME)
  1186.     gintCYDLGFRAME% = GetSystemMetrics(SM_CYDLGFRAME)
  1187.     gintCYCURSOR% = GetSystemMetrics(SM_CYCURSOR)
  1188.     gintCXVSCROLL% = GetSystemMetrics(SM_CXVSCROLL)
  1189.     gintCYHSCROLL% = GetSystemMetrics(SM_CYHSCROLL)
  1190. End Sub
  1191.  
  1192. Sub SetTextBoxReadOnly (DstTextBox As TextBox, intFlag As Integer)
  1193.     Dim lngReturnCode As Long
  1194.     Select Case intFlag%
  1195.     Case True
  1196.     lngReturnCode& = SendMessage(DstTextBox.hWnd, EM_SETREADONLY, 1, ByVal 0&)
  1197.     Case False
  1198.     lngReturnCode& = SendMessage(DstTextBox.hWnd, EM_SETREADONLY, 0, ByVal 0&)
  1199.     End Select
  1200. End Sub
  1201.  
  1202. Sub ShowToolTips (DstControl As Control, strMsg As String)
  1203.     Dim mPoint          As tagPoint
  1204.     Dim pRect           As tagRECT
  1205.     Dim intTmpLeft      As Integer
  1206.     Dim intTmpWidth     As Integer
  1207.     Dim intTmpTop       As Integer
  1208.     Dim intTmpHeight    As Integer
  1209.     
  1210.     If GetActiveWindow() <> DstControl.Parent.hWnd Then Exit Sub
  1211.     Load frmToolTips
  1212.     frmToolTips.AutoRedraw = True
  1213.     frmToolTips.Cls
  1214.     GetCursorPos mPoint
  1215.     GetWindowRect DstControl.hWnd, pRect
  1216.     
  1217.     intTmpLeft% = (pRect.Left + (pRect.Right - pRect.Left) \ 3) * Screen.TwipsPerPixelX
  1218.     intTmpWidth% = frmToolTips.TextWidth(strMsg$) + 2 * (gintCXBORDER + 3) * Screen.TwipsPerPixelX
  1219.     intTmpTop% = (mPoint.y + gintCYCURSOR) * Screen.TwipsPerPixelY
  1220.     intTmpHeight% = frmToolTips.TextHeight(strMsg$) + 2 * (gintCYBORDER + 2) * Screen.TwipsPerPixelY
  1221.     If intTmpLeft% < 0 Then intTmpLeft% = 0
  1222.     If intTmpLeft% > Screen.Width - intTmpWidth% Then intTmpLeft% = Screen.Width - intTmpWidth%
  1223.     If intTmpTop% > Screen.Height - intTmpHeight% Then intTmpTop% = pRect.Top * Screen.TwipsPerPixelY - intTmpHeight%
  1224.  
  1225.     'Does not work properly when old version of 3DWin (shareware) is running.
  1226.     frmToolTips.Move intTmpLeft%, intTmpTop%, intTmpWidth%, intTmpHeight%
  1227.     frmToolTips.CurrentX = 3 * Screen.TwipsPerPixelX
  1228.     frmToolTips.CurrentY = 2 * Screen.TwipsPerPixelY
  1229.     frmToolTips.Print strMsg$
  1230.     frmToolTips.AutoRedraw = False
  1231. End Sub
  1232.  
  1233.